package org.donhuan.rms.ui.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.donghuan.rms.framework.domain.Country;
import org.donghuan.rms.framework.domain.EntityListenerAdapter;
import org.donghuan.rms.framework.domain.IDentity;
import org.donghuan.rms.framework.domain.Person;
import org.donghuan.rms.framework.domain.RecordFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.StructuredViewer;

public class DataFactory extends EntityListenerAdapter implements IAdaptable {
	private static DataFactory INSTANCE = null;
	private List<Country> countrylist;
	private String text;
	private StructuredViewer view;
	private List<String> items;
	private Map<String, Object> itemMap;
	private DataFactory() {
		itemMap=new HashMap<String, Object>();
		List<RecordFile> a=new ArrayList<RecordFile>();
		List<RecordFile> b=new ArrayList<RecordFile>();
		List<RecordFile> c=new ArrayList<RecordFile>();
		a.add(new RecordFile("a1"));
		a.add(new RecordFile("a2"));
		a.add(new RecordFile("a3"));
		b.add(new RecordFile("b1"));
		b.add(new RecordFile("b2"));
		b.add(new RecordFile("b3"));
		c.add(new RecordFile("c1"));
		c.add(new RecordFile("c2"));
		c.add(new RecordFile("c3"));
		itemMap.put("1", a);
		itemMap.put("2", b);
		itemMap.put("3", c);
		items=new ArrayList<String>();
		for(String item:itemMap.keySet()){
			items.add(item);
		}
	}
	public Map<String,Object> getItemMap(){
		return this.itemMap;
	}
	public List<String> getItems(){
		return items;
	}
	public static DataFactory getInstance() {
		if (INSTANCE == null)
			INSTANCE = new DataFactory();
		return INSTANCE;
	}

	public List<Country> creatTreeData() {
		countrylist = new ArrayList<Country>();
		Country gz = new Country();
		Country py = new Country();
		countrylist.add(gz);
		countrylist.add(py);
		Person maya = new Person();
		maya.setiDentity(new IDentity("maya"));
		maya.setNickName("xgq");
		maya.setCreateDate(new Date());
		Person flay = new Person();
		flay.setiDentity(new IDentity("flay"));
		flay.setNickName("zlm");
		flay.setCreateDate(new Date());
		Person jerry = new Person();
		jerry.setiDentity(new IDentity("jerry"));
		jerry.setNickName("xqy");
		jerry.setCreateDate(new Date());
		List<Person> personlist = new ArrayList<Person>();
		List<Person> personlist1 = new ArrayList<Person>();
		personlist.add(maya);
		personlist.add(flay);
		personlist.add(jerry);
		gz.setName("gz");
		gz.setPersons(personlist);
		Person tom=new Person("Tom", "tom", new Date());
		personlist1.add(tom);
		py.setName("py");
		py.setPersons(personlist1);

		return countrylist;
	}

	@SuppressWarnings("rawtypes")
	public Object getAdapter(Class adapter) {
		// TODO Auto-generated method stub
		return null;
	}

	public StructuredViewer getView() {
		return view;
	}

	public void setView(StructuredViewer view) {
		this.view = view;
	}


	public String getText() {
		return this.text;
	}

	public void setText(String text) {
		this.text = text;
	}
	public List<Country> getCountries(){
		return this.countrylist;
	}
	public void remove(Country country){
		countrylist.remove(country);
	}

	public void addChild(Country country) {
		countrylist.add(country);
		firePropertyChanged();
		
	}
	public Object getRecordFiles(String key) {
		return itemMap.get(key);
	}
	public void setItems(List<String> items) {
		this.items=items;
	}
}
